/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package tubesif2050;

import java.io.*;

/**
 *
 * @author Toshiba
 */
public class Window1 extends javax.swing.JFrame {

    /**
     * Creates new form Window1
     */
    public Window1(String title) {
        super(title);
        initComponents();
    }

    /**
     * This method is called from within the constructor to initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is always
     * regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        jFrame1 = new javax.swing.JFrame();
        jOpen = new javax.swing.JFileChooser();
        jFrame2 = new javax.swing.JFrame();
        jSave = new javax.swing.JFileChooser();
        jInternalFrame1 = new javax.swing.JInternalFrame();
        jPanel1 = new javax.swing.JPanel();
        rdoRel = new javax.swing.JRadioButton();
        rdoPro = new javax.swing.JRadioButton();
        jPanel2 = new javax.swing.JPanel();
        jLabel1 = new javax.swing.JLabel();
        jScrollPane1 = new javax.swing.JScrollPane();
        txtPrem = new javax.swing.JTextArea();
        jPanel3 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jScrollPane2 = new javax.swing.JScrollPane();
        txtGoal = new javax.swing.JTextArea();
        jPanel4 = new javax.swing.JPanel();
        btnProve = new javax.swing.JButton();
        btnKill = new javax.swing.JButton();
        jMenuBar1 = new javax.swing.JMenuBar();
        mFile = new javax.swing.JMenu();
        mNew = new javax.swing.JMenuItem();
        mOpen = new javax.swing.JMenuItem();
        mSave = new javax.swing.JMenuItem();
        mSaveAs = new javax.swing.JMenuItem();
        jSeparator1 = new javax.swing.JPopupMenu.Separator();
        mClose = new javax.swing.JMenuItem();
        jSeparator2 = new javax.swing.JPopupMenu.Separator();
        mExit = new javax.swing.JMenuItem();
        mHelp = new javax.swing.JMenu();
        mHelpContent = new javax.swing.JMenuItem();
        mCredit = new javax.swing.JMenu();
        mAuthor = new javax.swing.JMenuItem();

        jFrame1.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jFrame1.setTitle("Open");
        jFrame1.setMinimumSize(new java.awt.Dimension(700, 350));

        jOpen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jOpenActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jFrame1Layout = new javax.swing.GroupLayout(jFrame1.getContentPane());
        jFrame1.getContentPane().setLayout(jFrame1Layout);
        jFrame1Layout.setHorizontalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 586, Short.MAX_VALUE)
            .addGroup(jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jFrame1Layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(jOpen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );
        jFrame1Layout.setVerticalGroup(
            jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 377, Short.MAX_VALUE)
            .addGroup(jFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jFrame1Layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(jOpen, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );

        jFrame2.setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        jFrame2.setTitle("Save As");
        jFrame2.setMinimumSize(new java.awt.Dimension(700, 350));

        jSave.setApproveButtonText("Save");
        jSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jSaveActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jFrame2Layout = new javax.swing.GroupLayout(jFrame2.getContentPane());
        jFrame2.getContentPane().setLayout(jFrame2Layout);
        jFrame2Layout.setHorizontalGroup(
            jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 586, Short.MAX_VALUE)
            .addGroup(jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jFrame2Layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(jSave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );
        jFrame2Layout.setVerticalGroup(
            jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGap(0, 377, Short.MAX_VALUE)
            .addGroup(jFrame2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(jFrame2Layout.createSequentialGroup()
                    .addGap(0, 0, Short.MAX_VALUE)
                    .addComponent(jSave, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addGap(0, 0, Short.MAX_VALUE)))
        );

        setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setMinimumSize(new java.awt.Dimension(500, 600));

        jInternalFrame1.setMinimumSize(new java.awt.Dimension(500, 600));
        jInternalFrame1.setVisible(false);
        jInternalFrame1.addInternalFrameListener(new javax.swing.event.InternalFrameListener() {
            public void internalFrameClosed(javax.swing.event.InternalFrameEvent evt) {
                jInternalFrame1InternalFrameClosed(evt);
            }
            public void internalFrameClosing(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameOpened(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameActivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeactivated(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameDeiconified(javax.swing.event.InternalFrameEvent evt) {
            }
            public void internalFrameIconified(javax.swing.event.InternalFrameEvent evt) {
            }
        });

        buttonGroup1.add(rdoRel);
        rdoRel.setSelected(true);
        rdoRel.setText("Relational");

        buttonGroup1.add(rdoPro);
        rdoPro.setText("Proporsitional");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(rdoRel)
                .addGap(18, 18, 18)
                .addComponent(rdoPro)
                .addGap(5, 5, 5))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel1Layout.createSequentialGroup()
                .addGap(0, 7, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(rdoRel)
                    .addComponent(rdoPro)))
        );

        jLabel1.setText("Premises");

        txtPrem.setColumns(20);
        txtPrem.setRows(5);
        jScrollPane1.setViewportView(txtPrem);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jScrollPane1)
                    .addGroup(jPanel2Layout.createSequentialGroup()
                        .addComponent(jLabel1)
                        .addGap(0, 0, Short.MAX_VALUE)))
                .addContainerGap())
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jLabel1)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane1, javax.swing.GroupLayout.DEFAULT_SIZE, 222, Short.MAX_VALUE)
                .addContainerGap())
        );

        jLabel2.setText("Goal");

        txtGoal.setColumns(20);
        txtGoal.setRows(5);
        jScrollPane2.setViewportView(txtGoal);

        javax.swing.GroupLayout jPanel3Layout = new javax.swing.GroupLayout(jPanel3);
        jPanel3.setLayout(jPanel3Layout);
        jPanel3Layout.setHorizontalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel2)
                .addGap(0, 0, Short.MAX_VALUE))
            .addComponent(jScrollPane2)
        );
        jPanel3Layout.setVerticalGroup(
            jPanel3Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel3Layout.createSequentialGroup()
                .addComponent(jLabel2)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 139, Short.MAX_VALUE))
        );

        btnProve.setText("Prove");
        btnProve.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnProveActionPerformed(evt);
            }
        });

        btnKill.setText("Kill");
        btnKill.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnKillActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel4Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(btnProve)
                .addGap(17, 17, 17)
                .addComponent(btnKill)
                .addContainerGap())
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addGroup(jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(btnProve)
                    .addComponent(btnKill))
                .addGap(0, 11, Short.MAX_VALUE))
        );

        javax.swing.GroupLayout jInternalFrame1Layout = new javax.swing.GroupLayout(jInternalFrame1.getContentPane());
        jInternalFrame1.getContentPane().setLayout(jInternalFrame1Layout);
        jInternalFrame1Layout.setHorizontalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel4, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                    .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
                .addContainerGap())
        );
        jInternalFrame1Layout.setVerticalGroup(
            jInternalFrame1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jInternalFrame1Layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap())
        );

        mFile.setText("File");

        mNew.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_N, java.awt.event.InputEvent.CTRL_MASK));
        mNew.setText("New");
        mNew.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mNewActionPerformed(evt);
            }
        });
        mFile.add(mNew);

        mOpen.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O, java.awt.event.InputEvent.CTRL_MASK));
        mOpen.setText("Open");
        mOpen.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mOpenActionPerformed(evt);
            }
        });
        mFile.add(mOpen);

        mSave.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.CTRL_MASK));
        mSave.setText("Save");
        mSave.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mSaveActionPerformed(evt);
            }
        });
        mFile.add(mSave);

        mSaveAs.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_S, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        mSaveAs.setText("Save As");
        mSaveAs.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mSaveAsActionPerformed(evt);
            }
        });
        mFile.add(mSaveAs);
        mFile.add(jSeparator1);

        mClose.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        mClose.setText("Close");
        mClose.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mCloseActionPerformed(evt);
            }
        });
        mFile.add(mClose);
        mFile.add(jSeparator2);

        mExit.setAccelerator(javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_X, java.awt.event.InputEvent.SHIFT_MASK | java.awt.event.InputEvent.CTRL_MASK));
        mExit.setText("Exit");
        mExit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mExitActionPerformed(evt);
            }
        });
        mFile.add(mExit);

        jMenuBar1.add(mFile);

        mHelp.setText("Help");

        mHelpContent.setText("Help Content");
        mHelpContent.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mHelpContentActionPerformed(evt);
            }
        });
        mHelp.add(mHelpContent);

        jMenuBar1.add(mHelp);

        mCredit.setText("Credit");
        mCredit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mCreditActionPerformed(evt);
            }
        });

        mAuthor.setText("Author");
        mAuthor.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                mAuthorActionPerformed(evt);
            }
        });
        mCredit.add(mAuthor);

        jMenuBar1.add(mCredit);

        setJMenuBar(jMenuBar1);

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jInternalFrame1, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jInternalFrame1, javax.swing.GroupLayout.PREFERRED_SIZE, 0, Short.MAX_VALUE)
        );

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void mOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mOpenActionPerformed
        // TODO add your handling code here:
        // new FileOpen().setVisible(true);
        jFrame1.setVisible(true);
    }//GEN-LAST:event_mOpenActionPerformed

    private void btnProveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnProveActionPerformed
        // TODO add your handling code here:
        if (currentfile == null) {
            javax.swing.JOptionPane.showMessageDialog(null,"Please save your file first, then click Prove again","Message Log",0);
            mSaveAsActionPerformed(evt);
        }
        else {
        FileWriter dataoutput;
        FileReader datainput;
        String output2 = "";
            try{
                dataoutput = new FileWriter(currentfile.getName());
                dataoutput.write("formulate(dream).\r\n"+txtPrem.getText()+"\r\nend_of_dream.\r\nformulate(destiny).\r\n"+txtGoal.getText()+"\r\nend_of_destiny.");
                dataoutput.close();
                datainput = new FileReader("tes1.out");
                int temp = 0;
                while(temp != -1){
                    temp = datainput.read();
                    if(temp != -1) output2 += (char)temp;
                }
            } catch(IOException e){
            }
        String output = "";
        try {
            String line;
            if (rdoRel.isSelected()){
                p = Runtime.getRuntime().exec("prover \"" + currentfile.getName() + "\"");
            } else if (rdoPro.isSelected()){
                p = Runtime.getRuntime().exec("prover \"" + currentfile.getName() + "\"");
            }
            BufferedReader bri = new BufferedReader
                (new InputStreamReader(p.getInputStream()));
            /*BufferedReader bre = new BufferedReader
                (new InputStreamReader(p.getErrorStream()));*/
            while ((line = bri.readLine()) != null) {
                output += (line + "\r\n");
            }
            bri.close();
            javax.swing.JOptionPane.showMessageDialog(null,"Process complete!","Message Log",1);
            //System.out.println("prover \"" + currentfile.getCanonicalPath() + "\"");
            System.out.println("Process completed");
            /*while ((line = bre.readLine()) != null) {
                System.out.println(line);
            }
            bre.close();*/
            p = Runtime.getRuntime().exec("del \"" + currentfile.getName() + "\"");
            p.waitFor();
        } catch (Exception e){
        }
        new Window2(output + "\r\n" + output2).setVisible(true);
        }
    }//GEN-LAST:event_btnProveActionPerformed

    private void mExitActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mExitActionPerformed
        // TODO add your handling code here:
        System.exit(0);
    }//GEN-LAST:event_mExitActionPerformed

    private void mCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mCloseActionPerformed
        // TODO add your handling code here:
        jInternalFrame1.setVisible(false);
        currentfile = null;
        txtPrem.setText("");
        txtGoal.setText("");
    }//GEN-LAST:event_mCloseActionPerformed

    private void mNewActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mNewActionPerformed
        // TODO add your handling code here:
        jInternalFrame1.setVisible(true);
    }//GEN-LAST:event_mNewActionPerformed

    private void jInternalFrame1InternalFrameClosed(javax.swing.event.InternalFrameEvent evt) {//GEN-FIRST:event_jInternalFrame1InternalFrameClosed
        // TODO add your handling code here:
        jInternalFrame1.setVisible(false);
    }//GEN-LAST:event_jInternalFrame1InternalFrameClosed

    private void mCreditActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mCreditActionPerformed
        // TODO add your handling code here:
    }//GEN-LAST:event_mCreditActionPerformed

    private void mAuthorActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mAuthorActionPerformed
        // TODO add your handling code here:
        new wAuthor().setVisible(true);
    }//GEN-LAST:event_mAuthorActionPerformed

    private void mSaveAsActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mSaveAsActionPerformed
        // TODO add your handling code here:
        if (!jInternalFrame1.isVisible()) javax.swing.JOptionPane.showMessageDialog(null,"No file to be saved!","Error Message",0);
        else {
            jFrame2.setVisible(true);
        }
    }//GEN-LAST:event_mSaveAsActionPerformed

    private void jOpenActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jOpenActionPerformed
        // TODO add your handling code here:
        if (javax.swing.JFileChooser.APPROVE_SELECTION.equals(evt.getActionCommand())) {
            // Open was clicked
            currentfile = jOpen.getSelectedFile();
            BufferedReader datainput;
            String premise = "Syntax error";
            String goal = "Syntax error";
            try {
                datainput = new BufferedReader(new FileReader(currentfile.getCanonicalPath()));
                assert (datainput != null);
                String Line = datainput.readLine();
                while ((!Line.contains("formulate(dream)."))){
                    Line = datainput.readLine();
                }
                if (Line.contains("formulate(dream).")) {
                    premise = "";
                    Line = datainput.readLine();
                    while ((!Line.contains("end_of_dream."))) {
                        premise += (Line + "\r\n");
                        Line = datainput.readLine();
                    }
                }
                txtPrem.setText(premise);
                Line = datainput.readLine();
                while ((!Line.contains("formulate(destiny)."))){
                    Line = datainput.readLine();
                }
                if (Line.contains("formulate(destiny).")) {
                    goal = "";
                    Line = datainput.readLine();
                    while ((!Line.contains("end_of_destiny."))) {
                        goal += (Line + "\r\n");
                        Line = datainput.readLine();
                    }
                }
                txtGoal.setText(goal);
            } catch (IOException e) {
            }
            jInternalFrame1.setVisible(true);
        } else if (javax.swing.JFileChooser.CANCEL_SELECTION.equals(evt.getActionCommand())) {
            // Cancel was clicked
        }
        jFrame1.setVisible(false);
    }//GEN-LAST:event_jOpenActionPerformed

    private void jSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jSaveActionPerformed
        // TODO add your handling code here:
        if (javax.swing.JFileChooser.APPROVE_SELECTION.equals(evt.getActionCommand())) {
            // Save was clicked
            currentfile = jSave.getSelectedFile();
            FileWriter dataoutput;
            try{
                dataoutput = new FileWriter(currentfile.getCanonicalPath());
                dataoutput.write("formulate(dream).\r\n"+txtPrem.getText()+"\r\nend_of_dream.\r\nformulate(destiny).\r\n"+txtGoal.getText()+"\r\nend_of_destiny.");
                dataoutput.close();
            } catch(IOException e){
            }
        } else if (javax.swing.JFileChooser.CANCEL_SELECTION.equals(evt.getActionCommand())) {
            // Cancel was clicked
        }
        jFrame2.setVisible(false);
    }//GEN-LAST:event_jSaveActionPerformed

    private void mSaveActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mSaveActionPerformed
        // TODO add your handling code here:
        if (!jInternalFrame1.isVisible()) javax.swing.JOptionPane.showMessageDialog(null,"No file to be saved!","Error Message",0);
        else {
            FileWriter dataoutput;
            if (currentfile == null) mSaveAsActionPerformed(evt);
            else {
                try{
                    dataoutput = new FileWriter(currentfile.getCanonicalPath());
                    dataoutput.write("formulate(dream).\r\n"+txtPrem.getText()+"\r\nend_of_dream.\r\nformulate(destiny).\r\n"+txtGoal.getText()+"\r\nend_of_destiny.");
                    dataoutput.close();
                } catch(IOException e){
                }
            }
        }
    }//GEN-LAST:event_mSaveActionPerformed

    private void btnKillActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_btnKillActionPerformed
        // TODO add your handling code here:
        if (p != null) {
            p.destroy();
            javax.swing.JOptionPane.showMessageDialog(null,"Process terminated!","Message Log",2);
            System.out.println("Process killed");
        }
    }//GEN-LAST:event_btnKillActionPerformed

    private void mHelpContentActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_mHelpContentActionPerformed
        // TODO add your handling code here:
        new wHelpContent().setVisible(true);
    }//GEN-LAST:event_mHelpContentActionPerformed
   
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        /*
         * Set the Nimbus look and feel
         */
        //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) ">
        /*
         * If Nimbus (introduced in Java SE 6) is not available, stay with the
         * default look and feel. For details see
         * http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html
         */
        try {
            for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
                if ("Nimbus".equals(info.getName())) {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                    break;
                }
            }
        } catch (ClassNotFoundException ex) {
            java.util.logging.Logger.getLogger(Window1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (InstantiationException ex) {
            java.util.logging.Logger.getLogger(Window1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (IllegalAccessException ex) {
            java.util.logging.Logger.getLogger(Window1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        } catch (javax.swing.UnsupportedLookAndFeelException ex) {
            java.util.logging.Logger.getLogger(Window1.class.getName()).log(java.util.logging.Level.SEVERE, null, ex);
        }
        //</editor-fold>

        /*
         * Create and display the form
         */
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                p = null;
                new Window1("TubesIF2050").setVisible(true);
            }
        });
    }
    
    public static File currentfile;
    public static Process p;
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JButton btnKill;
    private javax.swing.JButton btnProve;
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.JFrame jFrame1;
    private javax.swing.JFrame jFrame2;
    private javax.swing.JInternalFrame jInternalFrame1;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JMenuBar jMenuBar1;
    private javax.swing.JFileChooser jOpen;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JFileChooser jSave;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JPopupMenu.Separator jSeparator1;
    private javax.swing.JPopupMenu.Separator jSeparator2;
    private javax.swing.JMenuItem mAuthor;
    private javax.swing.JMenuItem mClose;
    private javax.swing.JMenu mCredit;
    private javax.swing.JMenuItem mExit;
    private javax.swing.JMenu mFile;
    private javax.swing.JMenu mHelp;
    private javax.swing.JMenuItem mHelpContent;
    private javax.swing.JMenuItem mNew;
    private javax.swing.JMenuItem mOpen;
    private javax.swing.JMenuItem mSave;
    private javax.swing.JMenuItem mSaveAs;
    private javax.swing.JRadioButton rdoPro;
    private javax.swing.JRadioButton rdoRel;
    private javax.swing.JTextArea txtGoal;
    private javax.swing.JTextArea txtPrem;
    // End of variables declaration//GEN-END:variables
    
}
